package com.yuejian.neusoft.yuejian_24.model;

import com.yuejian.neusoft.yuejian_24.javaBean.Collected;
import com.yuejian.neusoft.yuejian_24.javaBean.March;
import com.yuejian.neusoft.yuejian_24.javaBean.Success;
import com.yuejian.neusoft.yuejian_24.listener.CollectedListener;
import com.yuejian.neusoft.yuejian_24.listener.ListListener;
import com.yuejian.neusoft.yuejian_24.listener.SuccessListener;
import com.yuejian.neusoft.yuejian_24.service.MarchService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by q4549 on 2017/10/13.
 */

public class MarchModel {
    private Retrofit retrofit;
    public MarchModel(){
        retrofit =new Retrofit.Builder()
                .baseUrl("http://10.0.2.2/yuejian/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    public void getmarchlist(final ListListener listener){
        MarchService marchService = retrofit.create(MarchService.class);
        Call call = marchService.getmarchlist();
        Callback<List<March>> callback = new Callback<List<March>>() {
            @Override
            public void onResponse(Call<List<March>> call, Response<List<March>> response) {
                listener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<List<March>> call, Throwable t) {

            }
        };
        call.enqueue(callback);
    }
    public void follow(String march_id, String uid, String type, final SuccessListener listener){
        MarchService marchService = retrofit.create(MarchService.class);
        Call call = marchService.follow(march_id,uid,type);
        Callback<Success> callback = new Callback<Success>() {
            @Override
            public void onResponse(Call<Success> call, Response<Success> response) {
                listener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<Success> call, Throwable t) {

            }
        };
        call.enqueue(callback);
    }

    public void isCollected(String march_id, String uid, String type, final CollectedListener listener){
        MarchService marchService = retrofit.create(MarchService.class);
        Call call = marchService.isCollected(march_id,uid,type);
        Callback<Collected> callback = new Callback<Collected>() {
            @Override
            public void onResponse(Call<Collected> call, Response<Collected> response) {
                listener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<Collected> call, Throwable t) {

            }
        };
        call.enqueue(callback);
    }
}
